let vars = {
  // url: 'http://127.0.0.1:6025/',
	url: 'http://172.16.3.123:6025/',
	hkUrl: 'https://172.21.0.138/vms/preview',
};
if (location.hostname === '172.16.3.123') {
	vars.url = 'http://172.16.3.123:6025/';
} else if (location.hostname === '172.16.3.201') {
	vars.url = 'http://172.16.3.201:6025/';
} else if (location.hostname === 'fulima.com') {
	//vars.url = 'https://fulima.com/dt/test1/';
    vars.url = 'https://www.fulima.com/dt/test1/';
}else{
  // vars.url = 'http://192.168.50.99:6025'
  //vars.url = 'https://fulima.com/dt/test1/';
  vars.url = 'https://www.fulima.com/dt/test1/';
}

/**
 * 向父页面发送消息
 * @param msg
 * @param option
 */
function sendMessageToBox(msg, option = {}) {
	if (typeof option !== 'object') {
		option = {};
	}

	if (window !== window.parent) {
		window.parent.postMessage(Object.assign({'message': msg}, option), '*');
	}
}


/**
 * 异步json获取
 * @desc 封装mui.ajax,预留app验证接口
 * @param {String} url 接口地址
 * @param {Object} param 发送数据
 *
 * @param {Function} [success] 成功回调
 * @param {Function} [error] 错误回调
 */
function getJson(url, param, success, error,token = false) {
  var ajaxUrl = '';
  if(url.endsWith('json')){
    ajaxUrl = '../../json/' + url
  }else{
    ajaxUrl = vars.url + url
  }
	$.ajax({
		type: 'GET',
    headers: {
		  token: token ? getToken() : 'skip'
    },
		url: ajaxUrl,
		data: param,
		dataType: 'json',
		success: function (data) {
			if (typeof success == 'function') {
				success(data);
			} else {
				console.info('send:' + JSON.stringify(param) + '\nto:' + url + '\nreturn:\n' + JSON.stringify(data, null, 4));
			}
		},
		error: function (msg) {
			if (typeof error == 'function') {
				error(msg);
			} else {
				console.error('send:' + JSON.stringify(param) + '\nto:' + url + '\nstatus:' + msg.status + '\nreturn:\n' + JSON.stringify(msg));
			}
		}
	});
}

/**
 * 获取userAgent
 * @return {{}}
 */
function getUserAgent() {
	let Sys = {};
	let ua = navigator.userAgent.toLowerCase();
	if (ua.match(/msie ([\d.]+)/)) {
		Sys.type = 'ie';
		Sys.no = ua.match(/msie ([\d.]+)/)[1];
	}
	if (ua.match(/firefox\/([\d.]+)/)) {
		Sys.type = 'firefox';
		Sys.no = ua.match(/firefox\/([\d.]+)/)[1];
	}
	if (ua.match(/chrome\/([\d.]+)/)) {
		Sys.type = 'chrome';
		Sys.no = ua.match(/chrome\/([\d.]+)/)[1];
	}
	if (ua.match(/opera.([\d.]+)/)) {
		Sys.type = 'opera';
		Sys.no = ua.match(/opera.([\d.]+)/)[1];
	}
	if (ua.match(/version\/([\d.]+).*safari/)) {
		Sys.type = 'safari';
		Sys.no = ua.match(/version\/([\d.]+).*safari/)[1];
	}

	return Sys;
}


let timesType = 0;

/**
 * 实时预警数据
 */
function getTimesData() {

}

/**
 * 处理富文本数据
 * @param str
 */
function dealEditorContent(str) {
	return str.replace(/api::/g, vars.url + '/api/BASE-SERVER/sys/oss/');
}

/*
* 获取菜单信息
* */
function getNavInfo() {
  //获取用户信息
  // getJson('/api/BASE-SERVER/sys/user/currentUser/',{},function (res) {
  //   if(res.data){
  //
  //     //非大屏用户跳转到登录页
  //     if(res.data.userType != '202'){
  //       localStorage.removeItem('navData')
  //       location.replace(vars.url)
  //     }else{

        //获取菜单数据
        let navData = localStorage.getItem('navData');
        if(navData){
          navData = JSON.parse(navData)
          let menuDom = $('.side_menu_item')
          for (let i = 0; i < navData.length; i++) {
            for (let j = 0; j < menuDom.length; j++) {
              if(menuDom[j].innerText.indexOf(navData[i].title) > -1){
                $(menuDom[j]).removeClass('hide')
              }
            }
          }
          $('.side_menu_item').not('.hide').eq(0).trigger('click');
        }else{
          getJson('/api/BASE-SERVER/sys/menu/nav',{},function (data) {
            let navJson = data.data;
            localStorage.setItem('navData',JSON.stringify(navJson));
            //判断菜单权限，显示隐藏按钮
            let menuDom = $('.side_menu_item')
            for (let i = 0; i < navJson.length; i++) {
              for (let j = 0; j < menuDom.length; j++) {
                if(menuDom[j].innerText.indexOf(navJson[i].title) > -1){
                  $(menuDom[j]).removeClass('hide')
                }
              }
            }
            $('.side_menu_item').not('.hide').eq(0).trigger('click');
            // $('#iframePage').attr('src',iframeSrc)
          },function () {
            localStorage.removeItem('navData')
            location.replace(vars.url)
          },true)
        }

  //     }
  //   }
  // },function () {
  //   localStorage.removeItem('navData')
  //   location.replace(vars.url)
  // },true)



}

/*获取token*/
function getToken() {
  debugger
  let token = localStorage.getItem('_token')
  return token || 'skip';
  /*if(token){

  }else{
    // let r=confirm("请先登录");
    // console.log(r);
    location.replace(vars.url)
  }*/
}
